home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 722 / 722.xpi / chrome / noscript.jar / content / noscript / noscript.js < prev    next >
Text File  |  2010-02-12  |  3KB  |  102 lines

  1. var noscriptUtil = {
  2.   chromeBase: "chrome://noscript/content/",
  3.   chromeName: "noscript",
  4.   get service() {
  5.     var ns = null;
  6.     for(var attempt=1; attempt <= 2 ;attempt++) {
  7.       try {
  8.         ns = Components.classes["@maone.net/noscript-service;1"].getService().wrappedJSObject;
  9.         break;
  10.       } catch(ex) {
  11.         dump(ex.message);
  12.         window.navigator.plugins.refresh();
  13.       }
  14.     }
  15.     if(ns != null) {
  16.       ns.init();
  17.     }
  18.     delete this.service;
  19.     return this.service = ns;
  20.   },
  21.   
  22.   get prompter() {
  23.     delete this.prompter;
  24.     return this.prompter =
  25.       Components.classes["@mozilla.org/embedcomp/prompt-service;1"
  26.           ].getService(Components.interfaces.nsIPromptService);
  27.   }
  28. ,
  29.   confirm: function(msg, persistPref, title) {
  30.     const ns = this.service; 
  31.     var alwaysAsk = { value: ns.getPref(persistPref, true) };
  32.      if((!alwaysAsk.value) || 
  33.         noscriptUtil.prompter.confirmCheck(window, title || "NoScript",
  34.           msg,
  35.           noscriptUtil.getString("alwaysAsk"), alwaysAsk)
  36.      ) {
  37.       ns.setPref(persistPref, alwaysAsk.value);
  38.       return true;
  39.     }
  40.     return false;
  41.   },
  42.  
  43.   getString: function(key, parms) {
  44.     return this.service.getString(key, parms);
  45.   }
  46. ,
  47.   openOptionsDialog: function(params) {
  48.     window.openDialog(
  49.         this.chromeBase + this.chromeName + "Options.xul", 
  50.         this.chromeName + "Options",
  51.         "chrome, dialog, centerscreen, alwaysRaised",
  52.         params);  
  53.   },
  54.   
  55.   openXssOptions: function() {
  56.     this.openOptionsDialog({tabselIndexes: [5, 2]});
  57.   },
  58.   openJarOptions: function() {
  59.     this.openOptionsDialog({tabselIndexes: [5, 3]});
  60.   },
  61.   openABEOptions: function(info) {
  62.     this.openOptionsDialog({
  63.         tabselIndexes: [5, 5],
  64.         callback: info ? function() { this.abeOpts.select(info.ruleset); } : null
  65.     });
  66.   }
  67. ,
  68.   openAboutDialog: function(params) {
  69.     window.open(
  70.       this.chromeBase + "about.xul", 
  71.       this.chromeName + "About",
  72.       "chrome,dialog,centerscreen");
  73.   }
  74. ,
  75.   openConsole: function() {
  76.     if (window.toJavaScriptConsole) {
  77.         toJavaScriptConsole();
  78.     } else {
  79.         window.open("chrome://global/content/console.xul", "_js_console_", "chrome,extrachrome,menubar,resizable,scrollbars,status,toolbar");
  80.     }
  81.   },
  82.   
  83.   openFaq: function(which) {
  84.     this.browse("http://noscript.net/faq#" + which);
  85.   },
  86.   
  87.   openHelp: function(section) {
  88.     this.browse("http://noscript.net/help/" + section);
  89.   },
  90.   
  91.   
  92.   browse: function(url, features) {
  93.     var w = this.service.dom.mostRecentBrowserWindow;
  94.     if(w && !w.closed && w.gBrowser) {
  95.       w.gBrowser.selectedTab = w.gBrowser.addTab(url);
  96.     } else {
  97.       window.open(url, "_blank", features || null)
  98.     }
  99.   }
  100.   
  101. };
  102.